\documentclass{article}
% \usepackage[top=2.2cm, bottom=2.2cm, left=3.5cm, right=3.5cm]{geometry}
\usepackage{geometry}
\geometry{
    % a4paper,.
    top=2.2cm, bottom=2.2cm, 
    left=3.5cm, right=3.5cm,
    % heightrounded,
    totalheight=infinite,  % 理论上允许无限高度（需谨慎使用）
    % totalheight=\maxdimen  % 理论上允许无限高度（需谨慎使用）
}

% % 临时调整页面高度
% \newgeometry{
%     top=2.2cm, bottom=2.2cm, 
%     left=3.5cm, right=3.5cm,
%     totalheight=\maxdimen  % 理论上允许无限高度（需谨慎使用）
% }

% \checkandfixthelayout
% \documentclass[a4paper]{article}
\usepackage[linesnumbered,ruled,vlined,algo2e]{algorithm2e}
% \SetAlgoLined：增添end行
% \DontPrintSemicolon：不显示行末尾的分号
% \SetKwInput{KwInput}{Input}：设置输入
% \SetKwInOut{KwInput}{Input}：设置输入输出
% ruled：标题左对齐，顶部和底部各添加一条线
% linesnumbered：显示行编号
\usepackage{ctex} %注意，这里必须引入ctex,否则中文内容无法输出
\SetKwRepeat{Do}{do}{while}
\SetKwFunction{Try}{try}
\SetKwFunction{Catch}{catch}
% \SetKwProg{TryCatch}{Try}{Catch}{}

\begin{document}

\begin{algorithm2e}[p]
    \SetAlgoLined
    \caption{API文档生成解析算法}
    \SetKwInOut{KwIn}{\textbf{输入}}
    \SetKwInOut{KwOut}{\textbf{输出}}	

    \KwIn{$library\_name$,$file\_name$,$function\_name$,$file\_path$}
    \KwOut{dictionary structure of containing API information:$analysis\_dict$}

    % 真正的函数体：
    \SetKwFunction{FMain}{analysis\_API\_document}
    \SetKwProg{Fn}{Function}{}{}
    \Fn{\FMain{self,library\_name,file\_name,function\_name,file\_path}}{
        out\_path $\gets$ Join(self.document\_hub\_path,library\_name) \\
        \textbf{try:} \\
        \Indp subprocess.check\_call([sys.executable, "-m", "pdoc","--no-show-source","-o", out\_path,file\_path]) \\
        \Indm
        \textbf{catch:} subprocess.CalledProcessError \\
             \tcp{报错信息写入log日志文件} 
        module\_name $\gets$ file\_name.split(".")[0] \\
    % doc\_path=OR(path.join(out\_path,library\_name+".html"),path.join(out\_path,library\_name+".html"))
    % sp $\gets$ Split(file_path,".")[0] \\
    sp $\gets$ Split(file\_path,".")[0] \\
    sp $\gets$ Replace(sp,"src/,"") \\
    sp $\gets$ Replace(sp,"lib/,"") \\
    sp $\gets$ Replace(sp, repo\_path + "/" + library\_name + "/", "") \\
    split $\gets$  Split(file\_path,"/")\\
    path0 $\gets$ Join(out\_path, sp + ".html") \\ %路径0
    path1 $\gets$ Join(out\_path, library\_name + ".html") \\%路径1
    path2 $\gets$ Join(out\_path, library\_name, split[-2], module\_name + ".html") \\%路径2
    path3 $\gets$  Join(out\_path, module\_name + ".html") \\%路径3
    doc\_path=None \\
    \ForEach{candidate\_path in [path0,path1,path2,path3]}{
        \If{check\_node\_exists(path,function\_name) is exists}
        {
            %   sub $\gets$ a - b
            % \Return{True}\\
            doc\_path $\gets$  candidate\_path \\
            \textbf{break}
        }
    }

    \If{doc\_path=="" OR doc\_path is NONE}
    {
        \tcp{缺少API生成文档，将缺少内容写入log日志文件} 
    }
	} \textbf{end} \\
    doc=pq(filename=doc\_path) \\
    function\_doc=doc.find("\#"+function\_name) \\

    function\_sig=function\_doc.find(".attr.function").remove('a')
    
    \SetKwFunction{FMain}{check\_node\_exists}
    \SetKwProg{Fn}{Function}{}{}
        \Fn{\FMain{self,file\_path,function\_name}}{
            \If{file\_path is exists}
            {
                %   sub $\gets$ a - b
                doc=pq(filename=file\_path)\\
                function\_node=doc.find("\#"+function\_name)\\
                \If{function\_node is exists}
                {
                    %   sub $\gets$ a - b
                    \Return{True}
                }
            }
            \Else
            {
                \Return{False}
            }
        }\textbf{end}
        
\end{algorithm2e}


% 恢复默认页面设置
% \restoregeometry
\end{document}    